#pragma once

#include <ppltasks.h>
#include <pplawait.h>
#include <Windows.h>
#include <future>
#include <experimental/generator>

enum class BomOperate
{
	Delete = 0, // 删除
	Append = 1, // 新增
	Ignore = 2, // 忽略
};

enum class CvtResult
{
	Success = 0, // 转换成功
	Ignore = 1, // 忽略转换
	Invalid = 2, // 无效编码
};

/// <summary>转换参数</summary>
struct CvtConf
{
	std::wstring root_folder; // 要转换的根目录
	std::vector<std::wstring> extensions; // 要转换的扩展名
	std::vector<std::wstring> excludes; // 要排除的目录名
	uint32_t code_page{ CP_ACP }; // 当前字符串编码
	bool scan_into_sub{ true }; // 是否扫描子目录
	BomOperate with_utf8_bom{ BomOperate::Delete }; // 0 删除 1 追加(插入) 2 忽略
	bool command_line{ false }; // 是否来自命令行
};

/// <summary>初始化对话框</summary>
/// <param name="dlg">对话框句柄</param>
/// <param name="config">转换配置</param>
void OnDialogInit(HWND dlg, const CvtConf& config);

/// <summary>浏览按钮点击</summary>
/// <param name="dlg">对话框句柄</param>
void OnBrowseClicked(HWND dlg);

/// <summary>转换按钮点击</summary>
/// <param name="dlg">对话框句柄</param>
/// <param name="config">转换配置</param>
void OnConvertClicked(HWND dlg, CvtConf config);

/// <summary>多字节转UTF8</summary>
/// <param name="file">文件绝对路径</param>
/// <param name="config">当前转换配置</param>
std::future<CvtResult> MbcsToUtf8(const std::wstring& file, const CvtConf& config);

/// <summary>在资源管理器中打开</summary>
/// <param name="folder">当前欲打开目录</param>
bool OpenFolder(const std::wstring& folder);

/// <summary>获取所有欲转换文件</summary>
/// <param name="config">当前转换配置</param>
std::experimental::generator<std::wstring> GetFiles(const CvtConf& config);

/// <summary>枚举欲转换目录</summary>
/// <param name="folder">当前欲转换目录</param>
/// <remarks>co_yield 不支持递归调用</remarks>
std::experimental::generator<std::wstring> EnumFolders(const std::wstring& folder);

/// <summary>枚举欲转换文件</summary>
/// <param name="folder">当前欲转换目录</param>
std::experimental::generator<std::wstring> EnumFiles(const std::wstring& folder);